﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace NamazVakti.Controls
{
    public class RemainingTimeLabel : Control
    {
        public void WriteRemainingTime(int totalMinute, int remainingMinute)
        {
            if (remainingMinute < 1) return;

            Brush backBrush;
            float rating = 1f - (float)remainingMinute / totalMinute;
            if (rating < 0.33)
                backBrush = new SolidBrush(Color.Green);
            else if (rating < 0.66)
                backBrush = new SolidBrush(Color.Yellow);
            else
                backBrush = new SolidBrush(Color.Red);

            string text = string.Format("Kalan {0} dk", remainingMinute);
            Brush TextBrush = new SolidBrush(Color.Black);
            Font fnt = new Font("Arial", 10, FontStyle.Regular);
            Graphics g = this.CreateGraphics();
            SizeF textSize = g.MeasureString(text, fnt);

            g.Clear(this.BackColor);
            g.FillRectangle(backBrush, new Rectangle(0, 0, (int)(Width * rating), Height));
            g.DrawRectangle(new Pen(Color.Black), this.ClientRectangle);
            g.DrawString(text, fnt, TextBrush,
                 new Rectangle(ClientRectangle.X + (int)(ClientRectangle.Width - textSize.Width) / 2, ClientRectangle.Y, (int)textSize.Width, ClientRectangle.Height));
            g.Dispose();
        }
    }
}
